package com.wn.procurement.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Supplier;
import com.wn.procurement.service.SupplierService;
import com.wn.procurement.vo.SupplierVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody @Validated Supplier supplier){
        supplierService.insert(supplier);
        return ResponseEntity.success;
    }

    @RequestMapping("/update")
    public ResponseEntity update(@RequestBody @Validated Supplier supplier){
        supplierService.update(supplier);
        return ResponseEntity.success;
    }

    @RequestMapping("/query")
    public ResponseEntity query(@RequestBody @Validated SupplierVo supplierVo){
        PageBean<Supplier> pageBean = supplierService.getByCondition(supplierVo);
        return new ResponseEntity(pageBean);
    }
}
